<template>
	<view>
		<view class="details">
			<view class="detail-item" style="padding-top: 20px;">
				<text>合同状态: {{ status }}</text>
			</view>
			<view class="detail-item">
				<text>姓名（工号）: {{ realName }} ({{ staffNum }})</text>
			</view>
			<view class="detail-item">
				<text>任职部门: {{ deptName }}</text>
			</view>
			<view class="detail-item">
				<text>担任岗位: {{ postName }}</text>
			</view>
			<view v-if="signdate" class="detail-item">
				<text>签订日期: {{ signdate }}</text>
			</view>
			<view class="detail-item">
				<text>合同有效期: {{ startdate }} 至 {{ enddate }}</text>
			</view>
			<view class="detail-item">
				<text>服务期履行记录: {{ record || "—" }}</text>
			</view>
			<view class="detail-item">
				<text>备注: {{ remark || "—" }}</text>
			</view>
			<view class="detail-item" style="padding-bottom: 20px;">
				<text>经办人: {{ operatorId }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getHrmContract
	} from "@/api/work/hrmContract";
	import {
		getDicts
	} from "@/api/system/dict/data.js";
	import isHaveBug from "../../../utils/bug";

	export default {
		data() {
			return {
				status: "",
				realName: "",
				staffNum: "",
				deptName: "",
				postName: "",
				signdate: "",
				startdate: "",
				enddate: "",
				record: "",
				remark: "",
				operatorId: "",
			};
		},
		onLoad(options) {
			const id = options.id;

			if (isHaveBug("HR-APP-015")) {
				uni.setNavigationBarTitle({
					title: "合同信息"
				})
			}

			Promise.all([getDicts("contract_status")])
				.then(([contractStatus]) => {
					this.contractStatus = contractStatus.data;
					this.fetchDetails(id);
				})
				.catch((error) => {
					console.error("Error loading dictionary data:", error);
				});
		},
		methods: {
			fetchDetails(id) {
				getHrmContract(id).then((response) => {
					const data = response.data;
					this.status = data.status || "";
					this.realName = data.realName || "";
					this.staffNum = data.staffNum || "";
					this.deptName = data.deptName || "";
					this.postName = data.postName || "";
					if (!isHaveBug("HR-APP-014")) {
						this.signdate = data.signdate || "";
					}

					this.startdate = data.startdate || "";
					this.enddate = data.enddate || "";
					if (isHaveBug("HR-APP-016")) {
						this.record = data.record || " ";
						this.remark = data.remark || " ";
					} else {
						this.record = data.record || "—";
						this.remark = data.remark || "—";
					}
					
					this.operatorId = data.operatorId || "";
					let status = this.contractStatus.find(
						(item) => item.dictValue == this.status
					);
					this.status = status.dictLabel;
				});
			},
		},
	};
</script>

<style scoped>
	/* 页面整体样式 */
	view {
		padding: 10px;
		background-color: #f5f5f5;
	}

	/* 返回按钮样式 */
	.back-button {
		margin-bottom: 20px;
		color: #007aff;
		font-size: 16px;
	}

	/* 详细信息样式 */
	.details {
		background-color: #ffffff;
		border-radius: 8px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
		/* padding: 20px; */
	}

	/* 每一项信息的样式 */
	.detail-item {
		/* margin-bottom: 10px; */
		font-size: 16px;
		line-height: 1;
	}

	.detail-item text {
		color: #333;
	}
</style>